using QNLua.CommonData;

namespace QNLua.DoAction
{

    public static class DoAction
    {
        public static void Execute(QNActionOption? action, Dictionary<string, object>? extraParams, object? context)
        {
            if (action == null)
            {
                return;
            }

            // 示例：获取游戏场景（伪代码）
            var gameScene = GetGameScene();
            var option = action.Option;

            // 示例：跨服检查（伪代码）
            if (CheckCrossServer(option, gameScene))
            {
                return;
            }

            // 示例：地图检查（伪代码）
            if (CheckExceptMap(option, gameScene))
            {
                return;
            }

            switch (action.Type)
            {
                case DoActionType.OpenWindow:
                    HandleOpenWindow(action, extraParams, gameScene);
                    break;

                case DoActionType.CloseWindow:
                    HandleCloseWindow(action, context);
                    break;

                case DoActionType.ShowTip:
                    HandleShowTip(action, gameScene);
                    break;

                    // 添加其他 ActionType 的处理逻辑...
            }
        }

        private static void HandleOpenWindow(QNActionOption action, Dictionary<string, object>? extraParams, object? gameScene)
        {
            if (action.Name == null)
            {
                Console.WriteLine("name is required for OpenWindow action.");
                return;
            }

            // 示例：处理参数和逻辑（伪代码）
            Console.WriteLine($"Opening window: {action.Name}");
        }

        private static void HandleCloseWindow(QNActionOption action, object? context)
        {
            if (action.Name != null)
            {
                Console.WriteLine($"Closing window: {action.Name}");
            }
            else
            {
                Console.WriteLine("No window name provided for CloseWindow action.");
            }
        }

        private static void HandleShowTip(QNActionOption action, object? gameScene)
        {
            if (action.Param != null)
            {
                Console.WriteLine($"Showing tip: {action.Param}");
            }
            else
            {
                Console.WriteLine("Tip is required for ShowTip action.");
            }
        }

        private static bool CheckCrossServer(ActionConditionOption? option, object? gameScene)
        {
            if (option == null)
            {
                return false;
            }

            // if (option.noCrossServer.HasValue && option.noCrossServer.Value)
            // {

            // }
            // 示例：跨服检查逻辑（伪代码）
            return false;
        }

        private static bool CheckExceptMap(ActionConditionOption? option, object? gameScene)
        {
            if (option == null)
            {
                return false;
            }
            // 示例：地图检查逻辑（伪代码）
            return false;
        }

        private static object? GetGameScene()
        {
            // 示例：获取游戏场景（伪代码）
            return null;
        }
    }
}